package net.gz01.wallet.web.controller.admin;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.tx.Tx;

import net.gz01.util.ZODate;
import net.gz01.wallet.common.PageRespon;
import net.gz01.wallet.common.ZOSearchCondition;
import net.gz01.wallet.web.controller.BaseController;
import net.gz01.wallet.web.model.AdminUser;
import net.gz01.wallet.web.model.HelpInfo;

public class HelpController extends BaseController {

	public void search() {
		List<HelpInfo> list = HelpInfo.dao.selectHelpType();
		setAttr("helptype",list);
		render("help/helpList.html");
	}

	public void listJson() {
		ZOSearchCondition sc = super.getSearchCondition();
		Page<HelpInfo> pageResult = HelpInfo.dao.search(sc);
		renderJson(new PageRespon(pageResult));
	}

	public void view() {
		HelpInfo hi = HelpInfo.dao.findById(getPara("id"));
		setAttr("helpinfo", hi);
		render("help/helpView.html");
	}

	public void addPage(){
		List<HelpInfo> list = HelpInfo.dao.selectHelpType();
		setAttr("helptype",list);
		render("help/helpAdd.html");
	}

	public void add(){
		AdminUser user = (AdminUser)getSession().getAttribute("loginAdminUser");
		HelpInfo helpInfo = getModel(HelpInfo.class);
		helpInfo.setContent(getPara("content"));
		helpInfo.setCreatetime(ZODate.getDateTime());
		helpInfo.setUpdatetime(ZODate.getDateTime());
		helpInfo.setEditor(user.getName());
		helpInfo.save();
		renderSuccess();

	}

	public void update(){
		HelpInfo helpInfo = getModel(HelpInfo.class);
		helpInfo.setContent(getPara("content"));
		helpInfo.setUpdatetime(ZODate.getDateTime());
		AdminUser user = (AdminUser)getSession().getAttribute("loginAdminUser");
		helpInfo.setEditor(user.getName());
		helpInfo.update();
		renderSuccess();
	}

	public void updatePage(){
		HelpInfo helpInfo = HelpInfo.dao.findById(getPara("id"));
		List<HelpInfo> list = HelpInfo.dao.selectHelpType();
		setAttr("helptype",list);
		setAttr("helpinfo", helpInfo);
		render("help/helpUpdate.html");
	}

	@Before(Tx.class)
	public void delete(){
		HelpInfo.dao.deleteById(getPara("id"));
		renderSuccess(false);
	}

}
